/*
 * Created on 16-07-2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package utiles.SQL;

/**
 * @author Virtual Dark Priest
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */


import utiles.exceptions.InternalErrorException;

import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.Connection;
import java.sql.SQLException;


/**
 * <p>Implementa un conjunto de operaciones comunes para los DAO</p>
 * 
 */
public final class GeneralOperations {

    private GeneralOperations() {}
    
    /**
     * It closes a <code>ResultSet</code> if not <code>null</code>.
     */
    public static void closeResultSet(ResultSet resultSet) 
        throws InternalErrorException {
        
        if (resultSet != null) {        
            try {
                resultSet.close();
            } catch (SQLException e) {
                throw new InternalErrorException(e);
            }        
        }
        
    }

    /**
     * It closes a <code>Statement</code> if not <code>null</code>.
     */
    public static void closeStatement(Statement statement) 
        throws InternalErrorException {
        
        if (statement != null) {        
            try {
                statement.close();
            } catch (SQLException e) {
                throw new InternalErrorException(e);
            }        
        }
        
    }
    
    /**
     * It closes a <code>Connection</code> if not <code>null</code>.
     */
    public static void closeConnection(Connection connection)
        throws InternalErrorException {
        
        if (connection != null) {        
            try {
                connection.close();
            } catch (SQLException e) {
                throw new InternalErrorException(e);
            }        
        }
        
    }

} 